# _ * _ coding:utf-8 _ * _
from tornado.escape import json_decode
from pymongo import Connection
import os

home_path = os.path.expanduser('~')
env_json = os.path.join(home_path, "environment.json")
env = json_decode(open(env_json).read())

db_host = env["DOTCLOUD_DB_MONGODB_HOST"]
db_port = int(env["DOTCLOUD_DB_MONGODB_PORT"])
db_username = env["DOTCLOUD_DB_MONGODB_LOGIN"]
db_password = env["DOTCLOUD_DB_MONGODB_PASSWORD"]

connection = Connection(db_host, db_port)
db_admin = connection["admin"]
if db_username:
    db_admin.authenticate(db_username, db_password)
db = connection["apply"]
